package com.collection.treemaps;

import java.util.TreeMap;

public class GetLowestHighestKeyTreeMapExample {
	public static void main(String[] args) {
		 
	    //create TreeMap object
	    TreeMap treeMap = new TreeMap();
	   
	    //add key value pairs to TreeMap
	    treeMap.put("1","One");
	    treeMap.put("3","Three");
	    treeMap.put("2","Two");
	    treeMap.put("5","Five");
	    treeMap.put("4","Four");
	   
	    /*
	      To get the lowest key currently stored in Java TreeMap use,
	      Object firstKey() method of TreeMap class.
	     
	      This method returns the first or lowest key currently stored in the
	      TreeMap object.    
	    */
	   
	    System.out.println("Lowest key Stored in Java TreeMap is : "
	                                                 + treeMap.firstKey());
	   
	    /*
	      To get the highest key currently stored in Java TreeMap use,
	      Object lastKey() method of TreeMap class.
	     
	      This method returns the last or highest key currently stored in the
	      TreeMap object.
	    */
	   
	    System.out.println("Highest key Stored in Java TreeMap is : "
	                                                   + treeMap.lastKey());
	 
	  }
}
